import { useAuthStore } from '@/store/modules/auth';

export function useAuth() {
  const authStore = useAuthStore();

  function hasAuth(codes: string | string[]) {
    if (!authStore.isLogin) {
      return false;
    }
    const { id,permissionList } = authStore.userInfo;
    // admin
    if(id == '1'){
      return true;
    }
    if(permissionList == undefined || permissionList.length == 0){
      return false;
    }
    if(!codes){
      return true;
    }
    if (typeof codes === 'string') {
      return (permissionList as string[]).includes(codes as string);
    }

    return (codes as string[]).some(code => permissionList.includes(code));
  }

  return {
    hasAuth
  };
}
